<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>

<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>


<title>添加用户</title>

<link rel="shortcut icon" href="favicon.ico"></link>
<link th:href="@{/css/bootstrap.min14ed.css}"
	href="css/bootstrap.min14ed.css" rel="stylesheet"></link>
<link th:href="@{/css/font-awesome.min93e3.css}"
	href="css/font-awesome.min93e3.css" rel="stylesheet"></link>
<link th:href="@{/css/plugins/iCheck/custom.css}"
	href="css/plugins/iCheck/custom.css" rel="stylesheet"></link>
<link th:href="@{/css/animate.min.css}" href="css/animate.min.css"
	rel="stylesheet"></link>
<link th:href="@{/css/plugins/simditor/simditor.css}" rel="stylesheet"
	type="text/css" href="css/plugins/simditor/simditor.css"></link>
<link th:href="@{/css/style.min862f.css}" href="css/style.min862f.css"
	rel="stylesheet"></link>

<link th:href="@{/css/layui.css}" href="css/layui.css" rel="stylesheet"></link>

</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight"
		style="width: 100%; ">


		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h3>
							新建/编辑用户
						</h3>

					</div>
					<div class="ibox-content">
						<form method="get" class="form-horizontal">
			
							<div class="form-group">
								<label class="col-sm-2 control-label">用户名</label>

								<div class="col-sm-4">
									<input id="userId" type="text" class="form-control"
										th:value="${user.userId}"></input>
								</div>
								<div class="col-sm-2">
									<span class="help-block m-b-none"><e style="color:red">*</e>必填！</span>
								</div>
							</div>
							
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">密码</label>

								<div class="col-sm-4">
									<input id="password" type="password" class="form-control"
										></input>
								</div>
								<div class="col-sm-2">
									<span class="help-block m-b-none"><e style="color:red">*</e>必填！</span>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">用户类型</label>
								<div class="col-sm-4">
									<select id="type" class="form-control m-b" name="account">
										

										<option value="0" th:selected="${user.isAdmin==0}" > 普通用户</option>
										<option value="1" th:selected="${user.isAdmin==1}" > 管理员</option>
									</select> 
								</div>
								<div class="col-sm-2">
									<span class="help-block m-b-none"><e style="color:red">*</e>必选！</span>
								</div>
							</div>
							<div id="noadmin">
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">企业名称</label>

								<div class="col-sm-4">
									<input id="companyName" type="text" class="form-control"
										th:value="${user.companyName}"></input>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">联系方式</label>

								<div class="col-sm-4">
									<input id="phoneNum" type="text" class="form-control"
										th:value="${user.phoneNum}"></input>
								</div>
							</div>
							</div>
							
							
							</div>	

							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<button class="btn btn-primary" type="submit" onclick="save();return false;">保存内容</button>
									<button class="btn btn-white" type="submit">取消</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>


	<script th:src="@{/js/jquery.min.js}" src="js/jquery.min.js"></script>
	<script th:src="@{/js/bootstrap.min.js}" src="js/bootstrap.min.js"></script>
	<script th:src="@{/js/content.min.js}" src="js/content.min.js"></script>
	<script th:src="@{/js/plugins/iCheck/icheck.min.js}"
		src="js/plugins/iCheck/icheck.min.js"></script>
	<script th:src="@{/layer/layer.js}" ssrc="layer/layer.js"></script>
	<script>
		
		
		function save() {
			var url;
			var userId = $("#userId").val();
			var userName = $("#userId").val();
			var userPasswd = $("#password").val();
			var isAdmin = $("#type").val();
			var companyName=$("#companyName").val();
			var phoneNum=$("#phoneNum").val();
			if(userIdC == null){
				url = "/register.do";
			}
			else{
				url=  "/updateUser";
			}
			if(userId == "" || userPasswd == "" ) {
				layer.msg('请输入用户名和密码！');
			} else if(isAdmin == "") {
				layer.msg("请选择用户类型！");
			} else {
				$.ajax({
					url :url,
					datatype : "json",
					data : {
						userId : userId,
						userName : userName,
						userPasswd : userPasswd,
						isAdmin : isAdmin,
						addType : "manager",
						companyName:companyName,
						phoneNum:phoneNum,
					},
					type : 'POST',
					async : false,
					success : function(data) {
						if (data.status != 10001) {//
							layer.msg(data.msg);  
						} else {
							layer.msg(data.msg, {
								  icon: 1,
								  time: 2000 
								}, function(){
									window.location.replace("/userlistPage")
								});  
						}
					}
				});
			}
		}
		function GetQueryString(name){
		     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		     var r = window.location.search.substr(1).match(reg);
		     if(r!=null)return  decodeURI(r[2]); return null;
		}
		var userIdC="";
		//alert(GetQueryString(变量));
		$(document).ready(function() {
			userIdC = GetQueryString("userId");
			if($("#type :selected").val() == 1){
				$("#noadmin").hide();
			}else{
				$("#noadmin").show();
			}
			
		});
		$("#type").change(function(){
			var a = $("#type :selected").val();
			if( a == 0){
				$("#noadmin").show();
			}
			else{
				$("#noadmin").hide();
			}
		});
	</script>
</body>


</html>
